//
//  StatusTopView.swift
//  SinaMicroblog
//
//  Created by 唐绍禹 on 15/8/6.
//  Copyright © 2015年 唐绍禹. All rights reserved.
//

import UIKit
import SDWebImage

class StatusTopView: UIView {
    
    var status: Status? {
        didSet{
            iconView.sd_setImageWithURL(NSURL(string: (status?.user?.profile_image_url!)!))
            nameLabel.text = status?.user?.name ?? ""
            memberIconView.image = status?.user?.mbrankImage
            vipIconView.image = status?.user?.vipImage
            //TODO:后面做
            timeLabel.text = "刚刚"
            sourceLabel.text = "微博.ocm"
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.yellowColor()
        
        perpareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func perpareUI() {
        
        addSubview(separatorView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(vipIconView)
        addSubview(memberIconView)
        addSubview(sourceLabel)
        addSubview(timeLabel)
        
        //自动布局
        
        separatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView:separatorView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 12, y: 0))
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 12, y: 0))
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLabel, size: nil, offset: CGPoint(x: 12, y: 0))
        memberIconView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: CGPoint(x: 8, y: 0))
        vipIconView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 8))
        
    }
    
    /// 头像
    private lazy var iconView: UIImageView = UIImageView()
    /// 姓名
    private lazy var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    ///时间
    private lazy var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    /// 来源标签
    private lazy var sourceLabel: UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    /// 会员图标
    private lazy var memberIconView: UIImageView = UIImageView(image: UIImage(named:"avatar_vip"))
    /// vip图标
    private lazy var vipIconView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    private lazy var separatorView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(white: 0.95, alpha: 1)
        return v
    }()
   
}
